package com.zhu.mapper;

import com.zhu.pojo.Order;
import com.zhu.pojo.Person;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    @Select("SELECT " +
            "    (SELECT COUNT(*) FROM WorkOrders WHERE status = '已派单' AND MONTH(creation_date) = MONTH(CURRENT_DATE()) AND YEAR(creation_date) = YEAR(CURRENT_DATE())) AS total_assigned," +
            "    (SELECT COUNT(*) FROM WorkOrders WHERE status = '未派单') AS total_not_assigned," +
            "    (SELECT COUNT(*) FROM WorkOrders WHERE status = '完成') AS total_completed;")
    public Map<String,Object> getOrderStatistics();

    @Select("select * from workorders where status='未派单'")
    public List<Order> unassigned();

    @Select("select business_name from businesses where id=#{id}")
    public String getbusname(Integer id);

    @Select("select name from personnel where id=#{id}")
    public String getpername(Integer id);

    @Select("select * from personnel")
    public List<Person> perlist();

    @Update("update workorders set personnel_id=#{personnel_id} ,status='已派单' where business_id=#{business_id}")
    public void paidan(Integer business_id,Integer personnel_id);

    @Select("select * from workorders where status='已派单'")
    public List<Order> assigned();

    @Update("update workorders set status='完成' where id=#{id}")
    public void shoudan(Integer id);
}
